package com.gitee.base.modules;

import com.gitee.base.modules.core.model.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.Stream;

public class BaseController {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    protected boolean isSuperAdmin(){
        SysUser sysUser = getLoginUser();
        if(sysUser==null || StringUtils.isBlank(sysUser.getRoleIds())) return false;
        if(Stream.of(sysUser.getRoleIds().split(",")).filter(r->r.equals("1")).findAny().isPresent()){
            return true;
        }
        return false;
    }

    protected SysUser getLoginUser(){
        return (SysUser) SecurityUtils.getSubject().getPrincipal();
    }

    protected Integer getLoginUserId(){
        if(getLoginUser()==null){
            return 0;
        }else{
            return getLoginUser().getId();
        }
    }
}
